package com.xlhj.rabbit.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Author: caijliu
 * @Date: 03/09/2021 9:29
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@RestController
@RequestMapping("/topic")
public class TopicProducerController {

    private static final String TOPIC_EXCHANGE_NAME = "topic-exchange";
    private static final String ROUTING_KEY_A = "topic.*.*";
    private static final String ROUTING_KEY_B = "*.*.rabbit";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMessage/{message}")
    public void sendMessage(@PathVariable String message) {
        String uuid = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(TOPIC_EXCHANGE_NAME, ROUTING_KEY_A, message, correlationData);
    }
}
